import java.net.MalformedURLException;
import java.rmi.NotBoundException;
import java.rmi.RemoteException;

public class ClientUser {

	/**
	 * @param args
	 * @throws NotBoundException 
	 * @throws MalformedURLException 
	 * @throws RemoteException 
	 */
	public static void main(String[] args) throws RemoteException, MalformedURLException, NotBoundException {
		
		String myName;
		int number;
		
		/*if (args.length != 1) {
			System.out.println("java Client <number>");
			return;
		}*/
		//myName = args[0];
		//number = Integer.getInteger(args[0]);
		number = 10000;
	
		// initialize the system
		Client.init();
		
		// look up the Integer object in the name server
		// if not found, create it, and register it in the name server
		SharedObject s = Client.lookup("Integer");
		if (s == null) {
			s = Client.create(new Integer(0));
			Client.register("Integer", s);
		}
		
		for (int i = 0; i < number; i++) {
			s.lock_read();
			System.out.println((Integer)s.obj);
			s.unlock();
			//System.out.println("between read and write");
			s.lock_write();
			s.obj = new Integer((Integer)s.obj + 1);
			System.out.println("obj = " + (Integer)s.obj);
			s.unlock();
		}
		s.lock_read();
		System.out.println("Last value: "+(Integer)s.obj);
		s.unlock();
	}

}
